package com.luo.service;

import com.luo.mapper.UserMapper;
import com.luo.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public Map<String,Object> selectUserList(String username,String phone,
                                             String departmentId, int page,
                                             int limit,
                                             String roleId){
        Map<String,Object> map = new HashMap<>();
        int index = (page-1)*limit;
        List<User> users = userMapper.selectUserList(username,phone,departmentId,index,limit,roleId);
//        int count = userMapper.selectUserCount()
        map.put("code",0);
        map.put("msg","");
//        map.put("count",count);
        map.put("data",users);
        return map;
    }

    public Map<String,Object> insert(User user){

        Map<String,Object> map = new HashMap<>();
        userMapper.insert(user);
        map.put("code",0);
        map.put("msg","新增用户成功");
//        map.put("count",count);
        map.put("data",user);
        return map;
    }

    public Map<String,Object> delete(Integer id){
        Map<String,Object> map = new HashMap<>();
        userMapper.delete(id);
        map.put("code",200);
        map.put("msg","删除数据成功");
        map.put("data",id);
        return map;
    }

    public Map<String,Object> update(User user){
        Map<String,Object> map = new HashMap<>();
        userMapper.update(user);
        map.put("code",200);
        map.put("msg","更新数据成功");
        map.put("data",user);
        return map;
    }

    public Map<String,Object> selectUsernames(){
        Map<String,Object> map = new HashMap<>();
        List<User> users = userMapper.selectUsernames();
        map.put("code",0);
        map.put("msg","");
        map.put("data",users);
        return map;
    }


}
